package cn.wolfcode.web.interceptor;

import cn.wolfcode.web.util.SessionUtil;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@Component
public class MyInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

       //判断是否动态资源
        if (handler instanceof HandlerMethod) {
            if (request.getSession().getAttribute(SessionUtil.USER) == null) {
                response.sendRedirect("/login.html");
                return false;
            }
        }
        //放行静/动态资源
        return true;
    }
}
